package com.xym.manage.controller.api;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.github.pagehelper.PageInfo;
import com.xym.common.bean.EasyUiResult;
import com.xym.manage.pojo.Content;
import com.xym.manage.service.ContentService;

@Controller
@RequestMapping("api/content")
public class ApiContentController {

	@Autowired
	private ContentService contentService;
	
	/**
	 * 初始化 查询 list
	 * @param categoryId
	 * @param page
	 * @param rows
	 * @return
	 */
	@RequestMapping(method=RequestMethod.GET)
	public ResponseEntity<List<Content>> queryContent(@RequestParam("categoryId")Long categoryId,
			@RequestParam(value="page",defaultValue="1")Integer page,@RequestParam(value="rows",defaultValue="10")Integer rows){
		
		try {
			Content content = new Content();
			content.setCategoryId(categoryId);
			
			PageInfo<Content> pageInfo = contentService.queryPageListByWhere(content, page, rows);
			if(pageInfo!=null){
				
				return ResponseEntity.status(HttpStatus.OK).body(pageInfo.getList());
			}
			return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
	}
}
